home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / copydsk.zip / COPYPROC.ASM < prev    next >
Assembly Source File  |  1990-03-11  |  6KB  |  233 lines

  1. ;*******************************************************************************
  2. ;
  3. ;  COPYPROC.ASM - companion assembly routines for COPYDISK.C
  4. ;
  5. ;  Procedures:
  6. ;
  7. ;     unsigned volcopy (int source, int target)
  8. ;
  9. ;        Duplicates volume label from the source drive to the target
  10. ;        drive.  If the source drive has no label, the procedure
  11. ;        will delete any existing label from the target.
  12. ;
  13. ;     int drvinfo (unsigned char drive, struct drvinfo_t * drv)
  14. ;
  15. ;        Returns a boolian value indicating the validity of the
  16. ;        specified drive.  If valid, fills the structure pointed to
  17. ;        by the drv parameter with information about the drive's
  18. ;        media type, total diskspace, total allocation and free
  19. ;        space.
  20. ;
  21. ;     void setint24 (int *)
  22. ;
  23. ;        Installs an interrupt 24 critical error handler.
  24. ;
  25. ;     void restint24 (void);
  26. ;
  27. ;        Restores old interrupt 24 critical error handler.
  28. ;
  29. ;
  30. ;*******************************************************************************
  31.  
  32.      TITLE COPYPROC
  33.  
  34.      .MODEL SMALL,C
  35.  
  36.      .DATA
  37.  
  38. xfcb     db    255         ;xfcb flag
  39.      db    5 dup (0)     ;reserved
  40.      db    8         ;volume attribute byte
  41.      db    1         ;drive code (0 = current)
  42.      db    11 dup ('?')     ;wildcard filename and extension
  43.      db    25 dup (0)     ;remainder of FCB (not used)
  44.  
  45. dtabuff  db    64 dup (0)     ;new dta: receives search results
  46.  
  47.  
  48.  
  49.  
  50.  
  51.      .CODE
  52.  
  53. int24     dd    0         ; address of original
  54.                  ; critical error handler
  55.  
  56. cerror     dd    0         ; far pointer to caller's
  57.                  ; critical error flag
  58.  
  59. drvstruct dd   0         ; far pointer to caller's
  60.                  ; drive info structure
  61.  
  62. cr    equ   0dh
  63. lf    equ   0ah
  64.  
  65. prompt     db    cr,lf,'Non-maskable Critical Error',cr,lf,'$'
  66.  
  67.  
  68. volcopy  PROC USES si di ds es, Drive1:WORD, Drive2:WORD
  69.      ;mov    dx,seg dtabuff
  70.      ;mov    ds,dx
  71.      mov   dx,offset dtabuff
  72.      mov   ah,1ah            ; set new dta address
  73.      int   21h
  74.  
  75.      mov   bx,Drive2        ; store target drive drive number (1 byte)
  76.      mov   xfcb+7,bl        ; to xFCB offset 7
  77.      mov   dx,offset xfcb
  78.      mov   ah,13H            ; Delete volume from target drive
  79.      int   21H
  80.  
  81.      mov   bx,Drive1        ; store source drive drive number
  82.      mov   xfcb+7,bl        ; to xFCB offset 7
  83.      mov   dx,offset xfcb
  84.      mov   ah,11h            ; dos find first
  85.      int   21h
  86.  
  87.      cld
  88.      mov   cx,11            ; max size of vol name
  89.      mov   si,offset dtabuff + 8  ;pos of vol name in dta
  90.      mov   di,offset xfcb+8
  91.      rep   movsb            ; copy volume name from dta to xfcb
  92.  
  93.      mov   bx,Drive2
  94.      mov   xfcb+7,bl
  95.  
  96.      mov   dx,offset xfcb        ; Create the new volume label file
  97.      mov   ah,16H            ; on target disk
  98.      int   21H
  99.      cmp   al,00h            ; error, prob empty volume name
  100.      jne   novol
  101.      mov   dx,offset xfcb        ; Close the file
  102.      mov   ah,10H
  103.      int   21H
  104. novol:     mov   ah,0
  105.      ret
  106. volcopy  ENDP
  107.  
  108. drvinfo  PROC USES bx ds di si, Drive:BYTE, DrvStru:PTR WORD
  109.      mov   ax,DrvStru
  110.      mov   word ptr cs:drvstruct,ax
  111.      mov   word ptr cs:drvstruct+2,ds
  112.  
  113.      mov   dl,Drive
  114.      mov   ah,1ch               ; get drive type
  115.      int   21h
  116.      cmp   al,0ffh               ; invalid drive or critical error?
  117.      je    error
  118.  
  119.      sub   ax,ax
  120.      mov   al,byte ptr ds:[bx]     ; points to media type info
  121.      lds   bx,cs:drvstruct
  122.      mov   word ptr ds:[bx],ax     ; store drive type in info structure
  123.  
  124.      mov   ah,36h               ; get drive allocation information
  125.      mov   dl,Drive
  126.      int   21h
  127.      cmp   ax,0ffffh           ; invalid drive or critical error?
  128.      jne   szok
  129. error:     cld
  130.      mov   ax,0               ; reset info structure to NULLs
  131.      mov   cx,7
  132.      mov   di,word ptr cs:drvstruct
  133.      rep   stosw
  134.      jmp   errexit               ; return FALSE
  135.  
  136. szok:     ; get total disk size
  137.      push  ax               ; sectors per cluster
  138.      push  bx               ; available clusters
  139.      push  dx               ; clusters per drive
  140.      pop   bx
  141.      mul   cx
  142.      mul   bx
  143.      lds   bx,cs:drvstruct
  144.      mov   word ptr ds:[bx+2], ax  ; lDiskSpace   (ax * cx * dx)
  145.      mov   word ptr ds:[bx+4], dx
  146.  
  147.      ; get total free
  148.      pop   bx
  149.      pop   ax
  150.      mul   cx
  151.      mul   bx
  152.      lds   bx,cs:drvstruct
  153.      mov   word ptr ds:[bx+10], ax ; lDiskFree    (ax * bx * cx)
  154.      mov   word ptr ds:[bx+12], dx
  155.  
  156.      ; calculate total allocated
  157.      mov   ax,word ptr ds:[bx+4]
  158.      sub   ax,word ptr ds:[bx+12]
  159.      xchg  ax,dx
  160.      mov   ax,word ptr ds:[bx+2]
  161.      sub   ax,word ptr ds:[bx+10]
  162.      jnc   skip
  163.      dec   dx
  164. skip:     mov   word ptr ds:[bx+6], ax  ; lDataSize
  165.      mov   word ptr ds:[bx+8], dx
  166.  
  167.      mov   ax,1               ; return TRUE
  168. errexit: ret
  169.  
  170. drvinfo ENDP
  171.  
  172. setint24 PROC USES ds di si, cflag:PTR WORD
  173.      mov   ax,cflag
  174.      mov   word ptr cs:cerror,ax
  175.      mov   word ptr cs:cerror+2,ds
  176.  
  177.      mov   ax,3524h            ; get critical error interrupt vector
  178.      int   21h
  179.  
  180.      mov   word ptr cs:int24,bx
  181.      mov   word ptr cs:int24+2,es
  182.  
  183.      push  cs
  184.      pop   ds
  185.      mov   dx,offset @code:criterr ; install our handler
  186.      mov   ax,2524h
  187.      int   21h
  188.  
  189.      ret
  190. setint24 ENDP
  191.  
  192. restint24 PROC USES ds di si
  193.      lds   dx,cs:int24
  194.      mov   ax,2524h            ; restore int 24 handler
  195.      int   21h
  196.      ret
  197. restint24 ENDP
  198.  
  199. criterr  proc  far
  200.      push  bx
  201.      push  cx
  202.      push  dx
  203.      push  si
  204.      push  di
  205.      push  bp
  206.      push  ds
  207.      push  es
  208.      test  ah, 00000001b           ; test for non-disk error (e.g. re-
  209.      jz    setflag               ; direction to off-line printer, etc)
  210. abort:     mov   ax,seg prompt
  211.      mov   ds,ax
  212.      mov   es,ax
  213.      mov   dx,offset prompt        ; display prompt
  214.      mov   ah,9
  215.      int   21h
  216.      mov   al,2               ; return ABORT code to dos kernel
  217.      jmp   exit
  218. setflag: lds   bx,cs:cerror           ; set critical error flag
  219.      mov   word ptr ds:[bx],1
  220. ignore:  mov   al,0               ; return IGNORE code to dos kernel
  221. exit:     pop   es
  222.      pop   ds
  223.      pop   bp
  224.      pop   di
  225.      pop   si
  226.      pop   dx
  227.      pop   cx
  228.      pop   bx
  229.      iret
  230. criterr  endp
  231.  
  232.      END
  233.